package com.gl.battleship.domain;

import org.springframework.core.ConstantException;

import com.gl.battleship.domain.exceptions.MessagesExceptions;
import com.gl.battleship.domain.exceptions.PlayerException;

public class Game {

	private Player playerOne;
	
	private Player playerTwo;
	
	private GameState stateGame;
	
	private Player turnoDisparar;
	
	private String warkToken;

	public String getWarkToken() {
		return warkToken;
	}

	public void setWarkToken(String warkToken) {
		this.warkToken = warkToken;
	}

	public Game(Player playerOne, Player playerTwo)  throws PlayerException {
		this.playerOne = playerOne;
		this.playerTwo = playerTwo;
		
		if(this.getPlayerOne().getUser().getNick().compareTo(this.getPlayerTwo().getUser().getNick()) == 0)
		{
			throw new PlayerException(MessagesExceptions.INVALID_OPPONENT);
		}
		this.stateGame = GameState.WAITING_TO_ACCEPT_WAR;
	}

	public Player getPlayerOne() {
		return playerOne;
	}


	public void setPlayerOne(Player playerOne) {
		this.playerOne = playerOne;
	}


	public Player getPlayerTwo() {
		return playerTwo;
	}


	public void setPlayerTwo(Player playerTwo) {
		this.playerTwo = playerTwo;
	}


	public GameState getStateGame() {
		return stateGame;
	}


	public void setStateGame(GameState stateGame) {
		this.stateGame = stateGame;
	}
	
	
	public Player getTurnoDisparar() {
		return turnoDisparar;
	}

	
	public void setTurnoDisparar(Player turnoDisparar) {
		this.turnoDisparar = turnoDisparar;
	}

	
	public Player getPlayerByUser(User user) throws PlayerException
	{
		if(this.getPlayerOne().getUser().getNick().equals(user.getNick()))
		{
			return this.playerOne;
		}
		
		if(this.getPlayerTwo().getUser().getNick().equals(user.getNick()))
		{
			return this.playerTwo;
		}

		throw new PlayerException(MessagesExceptions.NULL_USER_GAME);
	}

}
